namespace Web.Control.WWW.Wiki
{
    using System;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using Lx.Web.Common.UI;
    using Lx.Web.Common.ControlsUI;
    using System.Collections;
    using System.Collections.Generic;
    using System.Xml;
    using System.IO;

    using BLF;
    using BLF.WWW_WWW.Wiki;
    using Model.WWW_WWW.Wiki;

    public class Tags : BaseControl
    {
        protected Literal lUsers;
        protected Literal lCount;

        protected Repeater rptUsers;
        protected Repeater rptLB;

        protected int RecordCount = 0;
        protected int PageIndex = 1;
        protected string Learn = "";
        protected string BaseL = "";

        protected Literal lDLearn;
        protected Literal lDBaseL;

        protected override void OnLoad(EventArgs e)
        {
            int l = 10;
            if (lCount!=null) int.TryParse(lCount.Text, out l);
            int u= 10;
            if (lUsers != null) int.TryParse(lUsers.Text, out u);
            if (Request["p"] != null)
            {
                if (Request["p"] == "L")
                {
                    PageIndex = 999;
                }
                else
                {
                    int.TryParse(Request["p"], out PageIndex);
                }
            }

            if (lDLearn != null) Learn = lDLearn.Text;
            if (lDBaseL != null) BaseL = lDBaseL.Text;

            if (Request["l"] != null) Learn = Request["l"];
            if (Request["b"] != null) BaseL = Request["b"];
            if (PageIndex < 1) PageIndex = 1;

            ArrayList al = null;
            if (string.IsNullOrEmpty(Learn) || string.IsNullOrEmpty(BaseL) || Learn.Trim() == "" || BaseL.Trim()=="")
            {
                al = Wiki.GetTagsList(PageIndex, l, u);
            }
            else
            {
                al = Wiki.GetTagsList(Learn, BaseL, PageIndex, l, u);
            }
            if (rptLB != null&&al!=null&&al.Count==3)
            {
                rptLB.DataSource = (List<CategoryInfo>)al[0];
                rptLB.DataBind();
            }
            if (rptUsers != null)
            {
                rptUsers.DataSource = (List<UserInfo>)al[1];
                rptUsers.DataBind();
            }
            RecordCount = (int)al[2];
            int pCount = (int)Math.Ceiling(((decimal)RecordCount) / ((decimal)l));
            if (PageIndex > pCount) PageIndex = pCount;
            base.OnLoad(e);
        }
    }
}
